// 设备检测工具

// 检测是否为移动设备
export const isMobile = (): boolean => {
	return (
		window.innerWidth < 768 ||
		/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
	);
};

// 检测是否为平板设备
export const isTablet = (): boolean => {
	const width = window.innerWidth;
	return (width >= 768 && width < 992) || /iPad|Android(?!.*Mobile)/i.test(navigator.userAgent);
};

// 检测是否为桌面设备
export const isDesktop = (): boolean => {
	return (
		window.innerWidth >= 992 &&
		!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
	);
};

// 检测设备方向
export const isPortrait = (): boolean => {
	return window.innerHeight > window.innerWidth;
};

// 检测设备方向变化
export const onOrientationChange = (callback: () => void): void => {
	window.addEventListener('resize', callback);
};

// 移除设备方向变化监听
export const offOrientationChange = (callback: () => void): void => {
	window.removeEventListener('resize', callback);
};
